﻿using BusinessLayer.DatabaseEntities;
using BusinessLayer.VDataEntities;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace BusinessLayer
{
    public class AdminBusiness
    {
        public static VDataEntity Login(string userName, string password)
        {
            using (TrialManagementEntities entities = new TrialManagementEntities())
            {
                var validAdmin = from admin in entities.Admin
                                 where admin.UserName == userName && admin.Password == password
                                 && admin.IsActive == true
                                 select new VDataEntity() { ID = admin.ID, Name = admin.ChineseName };
                return validAdmin.FirstOrDefault();
            }
        }

        public static VDataEntity LoginByLDAP(string userName)
        {
            using (TrialManagementEntities entities = new TrialManagementEntities())
            {
                var validAdmin = from admin in entities.Admin
                                 where admin.UserName.ToUpper() == userName.ToUpper()
                                 && admin.IsActive == true
                                 select new VDataEntity() { ID = admin.ID, Name = admin.ChineseName };
                return validAdmin.FirstOrDefault();
            }
        }

        public static VDataEntity[] GetAdmins()
        {
            using(TrialManagementEntities entities = new TrialManagementEntities())
            {
                var admins = from admin in entities.Admin
                             where admin.IsActive == true
                             select new VDataEntity() { ID = admin.ID, Name = admin.ChineseName };
                return admins.ToArray();
            }
        }
    }
}
